<?php

namespace app\api\controller;

use app\api\Service\YubaoServer;
use app\common\controller\Api;
use app\api\Service\WeekbaoServer;
use app\api\Service\MonthbaoServer;
use app\api\Service\WavebaoService;

/**
 * 首页接口
 */
class Index extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }

    public function licaiconfig()
    {
        $weekbaoService  = new WeekbaoServer();
        $monthbaoService = new MonthbaoServer();
        $wavebaoService  = new WavebaoService();
        $yubaoService    = new YubaoServer();

        $weekbaoConfig = $weekbaoService->getWeekbaoConfig();
        $monthbaoConfig= $monthbaoService->getMonthbaoConfig();
        $wavebaoConfig = $wavebaoService->getWavebaoConfig();
        $yubaoConfig   = $yubaoService->getYubaoConfig();

        $week_rate = is_numeric($weekbaoConfig['week_rate']) ? $weekbaoConfig['week_rate'] : substr($weekbaoConfig['week_rate'],0,'-1');
        $month_rate = is_numeric($monthbaoConfig['month_rate']) ? $monthbaoConfig['month_rate'] : substr($monthbaoConfig['month_rate'],0,'-1');

        $weekbaoConfig['week_rate'] = substr(sprintf("%.3f",$week_rate * 7),0,-1).'%';
        $monthbaoConfig['month_rate'] = substr(sprintf("%.3f",$month_rate * 30),0,-1).'%';
        $this->success('成功',[
            'yubao' => $yubaoConfig,
            'week'  => $weekbaoConfig,
            'month' => $monthbaoConfig,
            'wave'  => $wavebaoConfig
        ]);

    }
}
